﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RSSReader.classesCustom;

namespace RSSReader.pageswithContent
{
    public partial class OnlineContent : System.Web.UI.Page
    {
        private UserDataHandler udh;        

        protected void Page_Load(object sender, EventArgs e)
        {
            //get object from session state
            udh = (UserDataHandler)Session["userDataHandler"];           
        }

        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (articlesGrid.SelectedRow == null)
            {
                FormView1.Visible = false;
            }
            else
            {
                FormView1.Visible = true;
            }

        }

        //protected void articlesGrid_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    //Object articleID = articlesGrid.SelectedDataKey.Value;
        //}


        protected void ObjectDataSourceForOnlineArticles_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            //do not create new object reuse the existing one
            e.ObjectInstance = udh;
        }

        protected void ObjectDataSourceArticleDetail_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
        {
            //do not create new object reuse the existing one
            e.ObjectInstance = udh;
        }

        protected void saveButton_Click(object sender, EventArgs e)
        {
            udh.saveUserCustomXMLArticle((Int32)articlesGrid.SelectedValue);            
        }

        protected void weblink_Command(object sender, CommandEventArgs e)
        {
            
            String link = e.CommandArgument.ToString();   
            //open link in new browser tab
            Response.Write("<script>window.open('"+link+"','_blank');</script>");            
        }

        /*
        protected void jumpButton_Click(object sender, EventArgs e)
        {
            Button bt = (Button)sender;
            FormView fv= (FormView)bt.NamingContainer;
            Label l= (Label)fv.FindControl("weblink");
            //or
            Label linkLabel = (Label)FormView1.FindControl("weblink");            
            //or
            Response.Redirect(dh.getXMLArticle(selectedXMLIndex).weblink);
        }
         * */

    }
}